home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / ramdisk2.zip / SETRAM.C < prev    next >
Text File  |  1986-12-02  |  2KB  |  112 lines

  1. /* Set the ramdisk to the specified number of kbytes */
  2. /* must be linked with -s1000 */
  3. /* written by John N. White */
  4.  
  5. unsigned size;
  6. unsigned zero[2],loci[256];
  7. int err,drive,loc,old;
  8.  
  9. main(argc,argv)
  10. char **argv;{
  11.     int i;
  12.     if(argc<2){
  13. usage:    puts("setram - program to set size of ramdisk in kbytes\n");
  14.         puts("usage:\n");
  15.         puts("setram drive kbytes    to allocate memory for ramdisk\n");
  16.         puts("setram drive           to free memory from ramdisk");
  17.         exit(1);
  18.     }
  19.     i=argv[1][0];
  20.     if(i>='a') i-=32;        /* set to upper case */
  21.     drive=i-'A'+1;
  22.     if(drive<0 || drive>31) goto usage;
  23.     getold();
  24.     if(old){
  25.         if(argc>2){
  26.             puts("ramdisk already has memory");
  27.             exit(1);
  28.         }
  29.         clear();
  30.         exit(0);
  31.     }
  32.     if(argc<3){
  33.         puts("no memory allocated to ramdisk");
  34.         exit(1);
  35.     }
  36.     size=atoi(argv[2]);
  37.     if(size<8 || size>800) goto usage;
  38.     loci[1]=size<<1;
  39.     size<<=6;
  40. #asm
  41.     mov        ah,4ah            ;modify programs allocated block
  42.     mov        cx,cs
  43.     sub        cx,10h
  44.     mov        word loc_,cx
  45.     mov        word loci_,cx
  46.     mov        es,cx            ;start of partition
  47.     mov        bx,word size_    ;new size
  48.     int        21h
  49.     jc        err
  50.  
  51.     mov        ax,cs            ;get pointer to environment block
  52.     sub        ax,10h
  53.     mov        es,ax
  54.     mov        es,es:[2Ch]
  55.     mov        ah,49h            ;dealloc environment block
  56.     int        21h
  57.     jc        err
  58.  
  59.     mov        ax,4405h        ;IOCTL call to ramdisk
  60.     mov        bx,word drive_
  61.     mov        dx,offset loci_
  62.     mov        cx,4
  63.     int        21h
  64.     jnc        ok
  65. err:
  66.     mov        word err_,ax
  67.     jmp        main_error_
  68. ok:
  69.     mov        ax,3100h
  70.     mov        dx,word size_
  71.     int        21h
  72.     jmp        err
  73. #
  74. error:
  75.     puts("error number ");
  76.     err&=63;
  77.     if(err>9) putchar(err/10+'0');
  78.     putchar(err%10+'0');
  79.     puts(" (decimal)");
  80.     exit(1);
  81. }
  82.  
  83. getold(){
  84. #asm
  85.     mov        ax,4404h        ;IOCTL call to ramdisk
  86.     mov        bx,word drive_
  87.     mov        dx,offset loci_
  88.     mov        cx,2
  89.     int        21h
  90.     jc        err
  91. #
  92.     old=loci[0];
  93. }
  94.  
  95. /* Clear the ramdisk */
  96. clear(){
  97. #asm
  98.     mov        ah,49h            ;free mem
  99.     mov        es,word old_
  100.     int        21h
  101.     jc        err
  102.  
  103.     mov        ax,4405h        ;IOCTL call to ramdisk
  104.     mov        bx,word drive_
  105.     mov        dx,offset zero_
  106.     mov        cx,4
  107.     int        21h
  108.     jc        err
  109. #
  110.     return;
  111. }
  112.